package com.ruoyi.applet.entity;


import java.util.Collections;
import java.util.List;

/**
 * @作者: JS
 * @创建时间: 2024年1月20日 19:54
 * @描述: 分页返回数据
 */
public class PageR<T> {
    
    private Integer pageNo = 1;
    
    private Integer pageSize = 20;
    
    private Integer total = 0;
    
    private Integer totalPages = 0;
    
    private List<T> result = Collections.emptyList();
    
    private Integer start = 1;
    
    private Integer end = 0;
    
    
    public void setReCords(List<T> result) {
        this.result = result;
    }
    
    public void setTotal(Integer total) {
        this.total = total;
        if (this.pageSize > 0) {
            this.totalPages = (total / this.pageSize) + (total % this.pageSize == 0 ? 0 : 1);
        } else {
            this.totalPages = 0;
        }
        this.start = (this.pageSize > 0 ? (this.pageNo - 1) * this.pageSize : 0) + 1;
        this.end = (this.start - 1 + this.pageSize * (this.pageNo > 0 ? 1 : 0));
    }
    
    public void setPageSize(Integer pageSize) {
        if (pageSize == null || pageSize < 1) {
            this.pageSize = 20;
        } else {
            this.pageSize = pageSize;
        }
        
    }
    
    public void setPageNo(Integer pageNo) {
        if (pageNo == null || pageNo < 1) {
            this.pageNo = 1;
        } else {
            this.pageNo = pageNo;
        }
    }
    
    
    // -- ------- ------------------------------------------------------------------------------------------------------------------------------------
    // -- Get Set ------------------------------------------------------------------------------------------------------------------------------------
    // -- ------- ------------------------------------------------------------------------------------------------------------------------------------
    public Integer getPageNo() {
        return pageNo;
    }
    public Integer getPageSize() {
        return pageSize;
    }
    public Integer getTotal() {
        return total;
    }
    public Integer getTotalPages() {
        return totalPages;
    }
    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }
    public List<T> getResult() {
        return result;
    }
    public void setResult(List<T> result) {
        this.result = result;
    }
    public Integer getStart() {
        return start;
    }
    public void setStart(Integer start) {
        this.start = start;
    }
    public Integer getEnd() {
        return end;
    }
    public void setEnd(Integer end) {
        this.end = end;
    }
}
